import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/login' // index.vue 是可以省略的
import Layout from '@/views/layout' // index.vue 是可以省略的
import Article from '@/views/article' //

// 二级路由显示
import Home from '@/views/home' // index.vue是可以省略的
import Video from '@/views/video' // index.vue是可以省略的
import Question from '@/views/question' // index.vue是可以省略的
import User from '@/views/user' // index.vue是可以省略的
Vue.use(VueRouter)

// 这个数组routes定义路由规则 约定什么地址指向那个组件
const routes = [
  // 用户登录
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/search/index.vue')
  },
  {
    path: '/search/result',
    name: 'searchResult',
    component: () => import('../views/search/result.vue') // 动态路由实现搜索解惑页面显示
  },
  // 这个路由是打算以动态路由的方式来传入文章编号
  {
    path: '/article/:id',
    name: 'article',
    component: Article
  },
  {
    path: '/user/profile',
    name: 'userProfile',
    component: () => import('@/views/user/profile.vue') // 编辑个人信息的路由
  },
  // 首页
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    children: [
      { path: '', component: Home }, // 默认显示的子路由
      { path: '/video', component: Video },
      { path: '/question', component: Question },
      { path: '/user', component: User }
    ]
  }
]
//  初始化路由实例
const router = new VueRouter({
  routes
})
export default router
